package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.OverflowListGoodsService;
import org.apache.shiro.web.session.HttpServletSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * User: fqy
 * Date: 2021/10/19
 * Time: 18:02
 * Describe: 商品报溢
 */
@RestController
@RequestMapping("overflowListGoods")
public class OverflowListGoodsController {
    @Autowired
    private OverflowListGoodsService overflowListGoodsService;

    //http://localhost:8080/overflowListGoods/save?overflowNumber=BY1605767033015

    /**
     * 新增报溢单
     * @param overflowList
     * @param overflowListGoodsStr
     * @return
     */
    @PostMapping("save")
    public ServiceVO saveOverflowListGoods(OverflowList overflowList, String overflowListGoodsStr, HttpSession session){
        User user = (User) session.getAttribute("currentUser");
        Integer userId = user.getUserId();
        overflowList.setUserId(userId);
        int i = overflowListGoodsService.saveOverflowListGoods(overflowList,overflowListGoodsStr);
        if(i == 0){
            return new ServiceVO(200, "保存失败");
        }
        return new ServiceVO(100, "保存成功");
    }

    /**
     * 根据时间范围查询报溢单
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("list")
    public Map<String,Object> getOverflowList(String sTime, String eTime){

        return overflowListGoodsService.getOverflowList(sTime,eTime);
    }

    /**
     * 根据overflowListId 报溢单商品信息 http://localhost:8080/overflowListGoods/goodsList
     * @param overflowListId
     * @return
     */
    @PostMapping("goodsList")
    public Map<String,Object> getOverflowListGoods(Integer overflowListId){

        return overflowListGoodsService.getOverflowListGoods(overflowListId);
    }
}
